package com.leyou.item.service;

import com.leyou.common.exception.MyException;
import com.leyou.item.pojo.Item;
import org.springframework.stereotype.Service;

import java.util.Random;

@Service
public class ItemService {

    public Item saveItem(Item item){
        if (item.getPrice() == null) {
//            throw new RuntimeException("价格不能为空");
            throw new MyException(444,"价格不能为空");
        }
        if (item.getName() == null || item.getName().isEmpty()) {
//            throw new RuntimeException("名称不能为空");
            throw new MyException(555,"名称不能为空");
        }
        int id = new Random().nextInt(100);
        item.setId(id);
        return item;
    }
}
